from typing import Optional, Dict, Type
from pydantic import BaseModel
from functools import wraps
from app import siwa
from flask import Blueprint


class NewBlueprint(Blueprint):
    tags = ['default']
    def __init__(self,*a,**k):
        if 'tags' in k:
            self.tags = k.pop('tags')

        super().__init__(*a,**k)
    def route(self,rule,
              *,
              query: Optional[Type[BaseModel]] = None,
              header: Optional[Type[BaseModel]] = None,
              cookie: Optional[Type[BaseModel]] = None,
              body: Optional[Type[BaseModel]] = None,
              form: Optional[Type[BaseModel]] = None,
              files=None,
              resp=None,
              x=[],
              tags=[],
              group=None,
              summary=None,
              description=None,
              **old_kwargs,
              ):
        def decorator(func):
            @wraps
            def inner(*args,**kwargs):
                tags = self.tags

                decarate_validate = siwa.doc(query,header,cookie,body,form,files,resp,x,tags,group,summary,description)

                f = decarate_validate(func)
                old = self.__old_route(rule,**old_kwargs)
                f = old(f)
                return f(*args,**kwargs)

            return inner

        return decorator

    def __old_route(self,rule,**kwargs):
        return super().route(rule, **kwargs)